package aes;


import client.ChatClient;
import client.gui.Client_GUI;
import client.gui.GUI_Login;
import client.gui.GUI_Teacher_Add_Question;
import database.JDBC;
import server.gui.Server_GUI;
import sharedspace.Question;
import sharedspace.User;

import fit.ActionFixture;

public class AddQuestionTests extends ActionFixture{
	
	Client_GUI client_GUI;
	Server_GUI server_GUI;
	User user;
	
	GUI_Teacher_Add_Question gui_Teacher_Add_Question;
	//run server
	public void startServer(String password)
	{
		server_GUI = new Server_GUI();
		server_GUI.getUserTextField().setText("root");
		server_GUI.getPWTextField().setText(password);
		server_GUI.getConnectBtn().doClick();
	}
	//run client with Teacher user
	public void startClient() throws Exception
	{
		client_GUI = new Client_GUI();
		client_GUI.connect();
		user = new User();
		user.setUserID("036855336");
		user.setUserFirstName("Maya");
		user.setUserLastName("Gal");
		user.setUserLogged(true);
		user.setUserPermission(2);
		user.setUserStatus("Active");
		
	}
	//run add question gui
	public void startAddQuestion()
	{
		gui_Teacher_Add_Question = new GUI_Teacher_Add_Question(client_GUI, user);
	}
	//add text of question
	public void addQuestion(String question)
	{
		gui_Teacher_Add_Question.textFielQuestion.setText(question);
		gui_Teacher_Add_Question.submitQuestion = question;
	}
	//add text of answer1
	public void addAnswer1(String answer1)
	{
		gui_Teacher_Add_Question.textFieldAnswer1.setText(answer1);
		gui_Teacher_Add_Question.submitAnswer[0] = answer1;
	}
	//add text of answer2
	public void addAnswer2(String answer2)
	{
		gui_Teacher_Add_Question.textFieldAnswer2.setText(answer2);
		gui_Teacher_Add_Question.submitAnswer[1] = answer2;
	}
	//add text of answer3
	public void addAnswer3(String answer3)
	{
		gui_Teacher_Add_Question.textFieldAnswer3.setText(answer3);
		gui_Teacher_Add_Question.submitAnswer[2] = answer3;
	}
	//add text of answer4
	public void addAnswer4(String answer4)
	{
		gui_Teacher_Add_Question.textFieldAnswer4.setText(answer4);
		gui_Teacher_Add_Question.submitAnswer[3] = answer4;
	}
	//select subject
	public void selectSubject(int index)
	{
		gui_Teacher_Add_Question.comboBoxTeacherSubject.setSelectedIndex(index);
	}
	//select answer
	public void selectCorrectAnswer(int index)
	{
		gui_Teacher_Add_Question.comboboxCorrectAnswer.setSelectedIndex(index);
	}
	//check all field are filed
	public boolean allFieldAreFilled()
	{
		return gui_Teacher_Add_Question.AllFieldsAreOk();
	}	
	//check question is filed
	public boolean checkQuestionFilled()
	{
		if (!gui_Teacher_Add_Question.submitQuestion.equals(""))
			return true;
		return false;
	}
	//check if user choose for subject form combobox
	public boolean isSubjectSelected()
	{
		int top = gui_Teacher_Add_Question.comboBoxTeacherSubject.getItemCount();
		return (gui_Teacher_Add_Question.comboBoxTeacherSubject.getSelectedIndex()>0 && gui_Teacher_Add_Question.comboBoxTeacherSubject.getSelectedIndex()<top);
	}
	//check if user choose for answer form combobox
	public boolean isCorrectAnswerSelected()
	{
		int top = gui_Teacher_Add_Question.comboboxCorrectAnswer.getItemCount();
		return (gui_Teacher_Add_Question.comboboxCorrectAnswer.getSelectedIndex()>0 && gui_Teacher_Add_Question.comboboxCorrectAnswer.getSelectedIndex()<top);
	}
	//insert question to database
	public void insertToDb()
	{
		gui_Teacher_Add_Question.btnOk.doClick();
	}
	//check if question inserted to database
	public boolean isInsertToDb()
	{
		return JDBC.existStatment("'"+gui_Teacher_Add_Question.questionID+"'", "q.questionID", "aes.question q");
	}

	

	
	
	
	
	
	
	
	
	
	
	

}
